package com.zhijian.warehouse.manage.entity.vo.response;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.zhijian.util.BeanUtil;
import com.zhijian.warehouse.manage.enums.ProductEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 仪器领用归记录 回显vo
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-28 17:42:45
 */
@Data
@Api(tags = "仪器领用归记录回显vo")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AccessProductRecordVo implements Serializable {

    private static final long serialVersionUID = -1;

    /**
     * 主键自增
     */
    @ApiModelProperty("主键自增")
    private Long id;

    /**
     * 领用单号
     */
    @ApiModelProperty("领用单号")
    private String drawNumber;

    /**
     * 归还单号
     */
    @ApiModelProperty("归还单号")
    private String backNumber;

    /**
     * 产品id
     */
    @ApiModelProperty("产品id")
    private Long productId;

    /**
     * 领用人id
     */
    @ApiModelProperty("领用人id")
    private Long drawUserId;

    /**
     * 领用时间 yyyy-MM-dd
     */
    @ApiModelProperty("领用时间 yyyy-MM-dd HH:mm:ss")
    @NotBlank(message = "领用时间 yyyy-MM-dd不能为空")
    private String drawTime;

    /**
     * 归还人id
     */
    @ApiModelProperty("归还人id")
    private Long backUserId;

    /**
     * 归还时间 yyyy-MM-dd
     */
    @ApiModelProperty("归还时间 yyyy-MM-dd HH:mm:ss")
    private String backTime;

    @ApiModelProperty("领用天数 单位 天")
    private Integer drawDay;

    @ApiModelProperty("计划归还时间 yyyy-MM-dd HH:mm:ss")
    private String planBackTime;


    /**
     * 备注
     */
    @ApiModelProperty("备注")
    private String msg;

    /**
     * 1= 领用 2 = 归还
     */
    @ApiModelProperty("1= 领用 2 = 归还")
    private Integer type;
    @ApiModelProperty("1= 领用 2 = 归还")
    private String typeStr;

    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    private String createTime;

    /**
     * 更新时间
     */
    @ApiModelProperty("更新时间")
    private String updateTime;

    @ApiModelProperty("产品名称")
    private String productName;
    @ApiModelProperty("产品名称")
    private String productNumber;
    @ApiModelProperty("产品RFID")
    private String productRfId;

    @ApiModelProperty("领用状态 USR_TYPE")
    private Byte useStatus;
    @ApiModelProperty("产品状态 PRO_STATUS")
    private Byte productStatus;


    private String productStatusStr;
    @ApiModelProperty("领用人")
    private String drawUserName;
    @ApiModelProperty("归还人")
    private String backUserName;

    @ApiModelProperty("超期时间")
    private Double overdueHours;

    @ApiModelProperty("进出时间")
    private String inOrOutTime;

    @ApiModelProperty("进出行为 DOOR_IN")
    private Integer inOrOutType;

    @ApiModelProperty("通道门ip")
    private String doorIpPort;

    @ApiModelProperty("限制天数")
    private String productLimitDay;

    @ApiModelProperty("领用时效限制")
    private String productLimitDayHours;
    @ApiModelProperty("产品规格")
    private String productModel;

    @Excel(name = "已领用时长", width = 20)
    private Double overdueTime;


    @ApiModelProperty("延长天数")
    private Integer extendDay;

    private String getProductLimitHour() {
        if (BeanUtil.isNotEmpty(this.productLimitDay))
            productLimitDayHours = String.valueOf(Integer.parseInt(this.productLimitDay) * 24);
        return "";
    }

    public String getTypeStr() {
        if (BeanUtil.isNotEmpty(this.type)) {
            Map<Integer, String> statusMap = new HashMap<>();
            statusMap.put(ProductEnum.UseStatusEnum.NO.getCode(), "归还");
            statusMap.put(ProductEnum.UseStatusEnum.YES.getCode(), "领用");
            return statusMap.get(this.type);
        }
        return typeStr;
    }

    public String getProductStatusStr() {
        if (BeanUtil.isNotEmpty(this.productStatus) && BeanUtil.isNotEmpty(ProductEnum.StatusEnum.getByCode(Integer.valueOf(this.productStatus)))) {
            return ProductEnum.StatusEnum.getByCode(Integer.valueOf(this.productStatus)).getDesc();
        }
        return productStatusStr;
    }
}
